<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Validate;
use \app\common\model\School as SchoolModel;

/**
 * 学校接口
 */
class School extends Api
{
    protected $noNeedLogin = ['schoolIndex'];
    protected $noNeedRight = '*';
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new SchoolModel();
    }

    /**
     * 获取学校列表
     * @ApiTitle    (获取学校列表)
     * @ApiParams (name="name", type="int", required=false, description="学校名称")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="查询成功")
     * @ApiReturn   ({
          'code':'200',
          'msg':'查询成功',
          'time': "",
          'data': $row
        })
     */
    public function schoolIndex()
    {
        $data = input('get.');
        $name = isset($data['name']) ? $data['name'] : '';
        // 如果有关键词，添加模糊搜索条件
        if ($name) {
            $dis = [
                'name' => ['like', "%{$name}%"],
            ];
            $row = $this->model->dataList($dis, "id, name");
        } else {
            $row = $this->model->dataList([], "id, name");
        }
        $this->success('查询成功', $row);
    }
}
